import * as actionTypes from './actionTypes';

const mutations = {
  setSearchVal: value => ({
    type:actionTypes.SET_SEARCHVAL,
    searchVal:value
  }),
  setSearchList: value => ({
    type:actionTypes.SET_SEARCHLIST,
    searchList:value
  })
};

const actions = {
  getSearchListAct: (value) => {
    return (dispatch,getState) => {
      dispatch(mutations.setSearchVal(value));
      fetch(`http://106.52.37.222:3000/books?bookName_like=${value}`)
      .then(response => response.json())
      .then(res => {
        // console.log(res);
        dispatch(mutations.setSearchList(res));
      })
    }
  }
};

export default actions;
